package com.example.xuegengwang.xuegengwang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;
import com.example.xuegengwang.xuegengwang.bean.FourPageListItemBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/2/28.
 */

public class FourListViewAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<FourPageListItemBean> arrayList;

    public FourListViewAdapter(Context context, ArrayList<FourPageListItemBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean isEnabled(int position) {
        return arrayList.get(position).isItem();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (arrayList.get(position).isItem()) {
            //如果是item
            myHolder myHolder = new myHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.four_fragment_list_item, null);
            myHolder.icon = (ImageView) convertView.findViewById(R.id.four_fragment_list_item_ima);
            myHolder.title = (TextView) convertView.findViewById(R.id.four_fragment_list_item_title);
            myHolder.more = (TextView) convertView.findViewById(R.id.four_fragment_list_item_more);
            myHolder.four_fragment_list_item_doc = (ImageView) convertView.findViewById(R.id.four_fragment_list_item_doc);
            myHolder.icon.setImageDrawable(arrayList.get(position).getIma());
            myHolder.title.setText(arrayList.get(position).getName());
            if (arrayList.get(position).getMore() != null) {
                myHolder.more.setText(arrayList.get(position).getMore());
            }else{
                myHolder.more.setVisibility(View.GONE);
            }
            if(arrayList.get(position).getCount()!=0){
                myHolder.four_fragment_list_item_doc.setVisibility(View.VISIBLE);
            }
            else{
                myHolder.four_fragment_list_item_doc.setVisibility(View.GONE);
            }
        } else {
            //如果是分隔条
            convertView = LayoutInflater.from(context).inflate(R.layout.four_fragment_list_item1, null);
        }
        return convertView;
    }

    class myHolder {
        ImageView four_fragment_list_item_doc;
        ImageView icon;
        TextView title;
        TextView more;
    }

}
